<html>
<head>
    <title>express sample</title>
    <style>
        pre
        {
            background-color: eeeeee;
        }
    </style>
</head>
<body>
    <h2>
        express</h2>
    <p>
        node.js apps that use the popular <a href="http://expressjs.com/">express</a> framework
        can be hosted in IIS.</p>
    <ul>
        <li>Express framework can be installed on Windows using NPM.</li>
        <li>Remember that you may or may not own the entire URL space within an express application
            when designing your URL structure - see code below.</li>
        <li>The URL rewrite module is recommended for all but the most simple express applications
            hosted in IIS. The sample below shows how to use it, but also check out the <a href="../urlrewrite/readme.htm">
                urlrewrite sample</a>.</li>
    </ul>
    visit the foo endpoint at <a href="myapp/foo">myapp/foo</a><br />
    visit the bar endpoint at <a href="myapp/bar">myapp/bar</a><br />
    visit the nonexistent endpoint at <a href="myapp/idontexist">myapp/idontexist</a><br />
    debug the application at <a href="hello.js/debug" target="_blank">hello.js/debug</a> (requires WebKit enabled browser)<br />
    <p>
        <b>code</b></p>
    <pre>var express = require('express');

var app = express.createServer();

app.get('/node/express/myapp/foo', function (req, res) {
    res.send('Hello from foo! [express sample]');
});

app.get('/node/express/myapp/bar', function (req, res) {
    res.send('Hello from bar! [express sample]');
});

app.listen(process.env.PORT);</pre>
    <p>
        <b>web.config</b></p>
    <pre>&lt;configuration&gt;
  &lt;system.webServer&gt;

    &lt;!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module --&gt;

    &lt;handlers&gt;
      &lt;add name="iisnode" path="hello.js" verb="*" modules="iisnode" /&gt;
    &lt;/handlers&gt;

    &lt;!-- use URL rewriting to redirect the entire branch of the URL namespace
    to hello.js node.js application; for example, the following URLs will 
    all be handled by hello.js:
    
        http://localhost/node/express/myapp/foo
        http://localhost/node/express/myapp/bar
        
    --&gt;

    &lt;rewrite&gt;
      &lt;rules&gt;
        &lt;rule name="myapp"&gt;
          &lt;match url="myapp/*" /&gt;
          &lt;action type="Rewrite" url="hello.js" /&gt;
        &lt;/rule&gt;
      &lt;/rules&gt;
    &lt;/rewrite&gt; 
    
  &lt;/system.webServer&gt;
&lt;/configuration&gt;</pre>
</body>
</html>
